package com.wangzhenyu.learn.test.java.io

import java.io.*
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

@Suppress("UNUSED")
object InstanceOutputStream {

    //FileOutputStream
    fun test01() {
        val path = "D:\\picture\\test1007.txt"
        var fileOutputStream: FileOutputStream? = null
        try {
            fileOutputStream = FileOutputStream(path, false)
            val temp = "I am your father"
            fileOutputStream.write(temp.toByteArray())
        } catch (e: Exception) {
            //
        } finally {
            fileOutputStream?.close()
        }
    }

    //ObjectOutputStream
    fun test02() {
        val path = "D:\\picture\\test.txt"
        var objectOutputStream: ObjectOutputStream? = null
        try {
            objectOutputStream = ObjectOutputStream(FileOutputStream(path))
            objectOutputStream.writeObject(StreamObject("WZY", 25))
        } catch (e: Exception) {
            //
        } finally {
            objectOutputStream?.close()
        }
    }

}

data class StreamObject(val name: String, val age: Int) : Serializable